package com.tw.management.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.tw.management.entity.User;
import com.tw.management.repository.UserDao;
import com.tw.management.service.UserService;

/**
 * 
 * @author TangW
 * @version 1.0
 *
 */
@Service("userService")
@Transactional
public class UserServiceImpl implements UserService {
	@Autowired
	private UserDao userDao;

	@Override
	public User findUserById(Long id) {
		return userDao.findUserById(id);
	}

	@Override
	public User findUserByEmail(String email) {
		return userDao.findUserByEmail(email);
	}

	@Override
	public User findUserByEmailAndPassword(String email, String password) {
		return userDao.findUserByEmailAndPassword(email, password);
	}

	@Override
	public List<User> listUsers() {
		return userDao.findAll();
	}

	@Override
	public User saveUser(User user) {
		return userDao.save(user);
	}

	@Override
	public int updateUserInfo(User user) {
		return userDao.updateUserInfo(user.getRealname(), user.getGender(), user.getBirthDate(), user.getMobile(), user.getId());
	}

	@Override
	public int updateUserPassword(User user) {
		return userDao.updateUserPassword(user.getPassword(), user.getId());
	}

	@Override
	public void deleteById(Long id) {
		userDao.delete(id);
	}
}
